// @ts-ignore
import {useViewTagsStore} from '@/store/modules/viewTags'
import {nextTick} from 'vue'

export function beforeEach(to: any, from: any) {
    var adminMain = document.querySelector('#adminui-main')
    const store = useViewTagsStore()
    if (!adminMain) {
        return false
    }
    store.updateViewTags({
        fullPath: from.fullPath,
        scrollTop: adminMain.scrollTop
    })
}

export function afterEach(to: any) {
    var adminMain = document.querySelector('#adminui-main')
    const store = useViewTagsStore()
    if (!adminMain) {
        return false
    }
    nextTick(() => {
        var beforeRoute = store.viewTags.filter((v: any) => v.fullPath == to.fullPath)[0]
        if (beforeRoute) {
            // @ts-ignore
            adminMain.scrollTop = beforeRoute.scrollTop || 0
        }
    })
}
